package org.nanotek.spring.integration;

import org.nanotek.util.Base;
import java.lang.reflect.Type;
import java.lang.reflect.ParameterizedType;
import java.util.Map;

import org.nanotek.cms.domain.lucene.Index;
import org.springframework.integration.Message;
import org.springframework.integration.support.MessageBuilder;

public class BaseMessageProducer <T extends Base<?>> implements MessageProducer<T>{

	public BaseMessageProducer() {
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BaseMessageProducer<Index> messageBuilder = new BaseMessageProducer<Index>();
		Class<?> mbClass = messageBuilder.getClass();
		Type clazz = mbClass.getGenericSuperclass();
		ParameterizedType type = (ParameterizedType) clazz;
		System.out.println(type.getActualTypeArguments()[0]);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
	}

	@Override
	public Message<?> getMessage(T obj) {
		MessageBuilder<?> messageBuilder = MessageBuilder.withPayload(obj);
		messageBuilder.build();
		return messageBuilder.build();
	}
	
	public  Message<?> getMessage(T obj , Map<String,Object> headers) 
	{ 
		MessageBuilder<?> mb = MessageBuilder.withPayload(obj);
		mb.copyHeaders(headers);
		return mb.build();
	}
	
}
